<script>
	var url;
	$(document).ready(function(){
	
		//Detail
		detailData = function (){
			var row = $('#dg').datagrid('getSelected');
			if (row){
				$('#dialog').dialog({
					title: 'Detail Data mahasiswa Pindahan',
					width: 700,
					height: 420,
					closed: true,
					cache: false,
					href: base_url+'mutasi_mahasiswa/detail/'+row.kd_mahasiswa,
					modal: true
				});
				
				$('#dialog').dialog('open');  
				url = base_url+'mutasi_mahasiswa/detail';
			}
		}
		
		actionbutton = function(value, row, index){
			var col;
			//if (row.kd_fakultas != null) {
			<?if($this->mdl_auth->CekAkses(array('menu_id'=>57, 'policy'=>'DETAIL'))){?>
				col = '<a href="#" onclick="detailData(\''+row.kd_mahasiswa+'\');" class="easyui-linkbutton" iconCls="icon-edit" plain="false">Detail</a>';
			<?}?>		
			//}
			return col;
		}
		
		// load grid
		$(function(){
			$('#dg').datagrid({url:"<?=base_url()?>mutasi_mahasiswa/grid_master"});	
			//$('#dg').datagrid('enableFilter'); 			
		});	
		
		// onchange
		$('#s_kd_fakultas').change(function(){
			$('#s_kd_prodi').load(base_url+'prosedur/getProdibyFakultas/'+$('#s_kd_fakultas').val());
		});
		
		// filter
		filter = function(){
			$('#dg').datagrid('load',{
				kd_fakultas : $('#s_kd_fakultas').val(),
				kd_prodi : $('#s_kd_prodi').val(),
				tahun : $('#s_tahun').val(),
			});
			//$('#dg').datagrid('enableFilter');
		}
		
		//# Tombol Bawah
		$(function(){
			var pager = $('#dg').datagrid().datagrid('getPager');	// get the pager of datagrid
			pager.pagination({
				buttons:[
					{
						iconCls:'icon-print',
						text:'Export PDF',
						handler:function(){
						var kd_fakultas = $('#s_kd_fakultas').val();
						var kd_prodi = $('#s_kd_prodi').val();
						var thn_angkatan = $('#s_tahun').val();
						if(kd_prodi !='' && thn_angkatan !='' ){
							window.open('<?=base_url().'mutasi_mahasiswa/laporan_pdf'?>/'+$('#s_kd_prodi').val()+'/'+$('#s_tahun').val());
						}
						else{
								$.messager.show({
									title: 'Warning',
									msg: 'Harap Isi Filter Terlabih Dahulu'
								});
							}
						}
					}
				]
			});			
		});
		
	});
</script>

<table id="dg" title="Kelola Data Mahasiswa Pindahan" data-options="
			rownumbers:true,
			singleSelect:true,
			autoRowHeight:false,
			pagination:true,
			pageSize:30,
			fit:true,
			toolbar:'#toolbar',
			">
	<thead>
		<tr>
			<!--<th field="tahun_penerimaan" sortable="true" width="80">Tahun Penerimaan</th> -->
			<th field="nim" sortable="true" width="125">NIM</th>
			<th field="nama" sortable="true" width="200">Nama</th>
			<th field="alamat" sortable="true" width="150">Alamat</th>
			<th field="no_telp" sortable="true" width="100">Telepon Siswa</th>
			<th field="asal_universitas" sortable="true" width="150">Asal Universitas</th>			
			<th field="action" align="center" formatter="actionbutton" width="100">Aksi</th>
		</tr>
	</thead>
</table>
<div id="toolbar" style="padding:5px;height:auto">
	<div style="margin-bottom:5px">
		
	</div>
	<div class="fsearch">
		<table width="700" border="0">
		  <tr>
			<td>Fakultas</td>
			<td>: 
				<select id="s_kd_fakultas" name="s_kd_fakultas" style="width:290px;">
					<?=$this->mdl_prosedur->OptionFakultas();?>
				</select>
			</td>
			<td>&nbsp;</td>
			<td>Tahun Angkatan</td>
			<td>: 
				<select id="s_tahun" name="s_tahun" style="width:100px;">
					<?=$this->mdl_prosedur->OptionTahunAngkatanM();?>
				</select>
			</td>
		  </tr>
		  <tr>
			<td>Program Studi</td>
			<td>: 
				<select id="s_kd_prodi" name="s_kd_prodi" style="width:290px;">
					<?=$this->mdl_prosedur->OptionProdi();?>
				</select>
			</td>
			<td>&nbsp;</td>
			<td>&nbsp;</td>
			<td>&nbsp;&nbsp;<a href="#" onclick="filter()" class="easyui-linkbutton" iconCls="icon-search">Filter</a></td>
		  </tr>
		</table>
	</div>
</div>
